#!/bin/sh
# This shell script will collect information
# from the users computer and compress it into
# a .zip file for e-mail to SMART Tech Support

# This file will copy all the files to a folder 
# so we can compress it into a nice little bundle

if [ $# = 0 ] ; then
  echo "USAGE: ArchiveLogs zipfile [file1] [file2]..."
  echo "where file1..N are extra files to add to the zip file."
  exit 1
fi

ZIPFILE="$1"
shift

# Create a unique directory to store files.
TMPDIR=`mktemp -d`
echo "tmp files copied to \"$TMPDIR\""

# SMARTBoardService.log and OneButtonReport files are passed in on the cmd line
while [ $# != 0 ] ; do
	echo "cp -f \"$1\" \"$TMPDIR\""
	cp -f "$1" "$TMPDIR"
	shift
done

#Get various logs
for i in kern.log messages syslog debug; do
	echo "cp -f /var/log/$i \"$TMPDIR\""
	cp -f /var/log/$i "$TMPDIR"
done

#Get the .plist files
echo "mkdir \"$TMPDIR/config/user\""
mkdir -p "$TMPDIR"/config/user
echo "mkdir \"$TMPDIR/config/global\""
mkdir -p "$TMPDIR"/config/global
echo "cp -f ~/.config/smarttech.conf \"$TMPDIR/config/user\""
cp -f ~/.config/smarttech.conf "$TMPDIR"/config/user/
echo "cp -f ~/.config/SMART Technologies/SMART Notebook.conf \"$TMPDIR/config/user\""
cp -f ~/.config/SMART\ Technologies/SMART\ Notebook.conf "$TMPDIR"/config/user/
echo "cp -f /etc/xdg/smarttech.conf \"$TMPDIR/config/global\""
cp -f /etc/xdg/smarttech.conf "$TMPDIR"/config/global/

# grab /etc/*-release
echo "cp -f /etc/*-release \"$TMPDIR\""
cp -f /etc/*-release "$TMPDIR"

# dump xdpyinfo
echo "xdpyinfo > \"$TMPDIR\"/xdpyinfo"
xdpyinfo > "$TMPDIR"/xdpyinfo

echo done copying files

# This program will create the .zip file that the user can e-mail to us
echo pushd .
pushd .
echo cd \"$TMPDIR\"
cd "$TMPDIR"
echo zip -r \"$ZIPFILE\" *
zip -r "$ZIPFILE" *
echo popd
popd
echo "rm -rd \"$TMPDIR\""
rm -rd "$TMPDIR"
